//
//  ZSY_UserView.m
//  ZSY_BreadTrip
//
//  Created by dllo on 15/12/29.
//  Copyright © 2015年 张诗宇. All rights reserved.
//

#import "ZSY_UserView.h"

@interface ZSY_UserView ()<UIGestureRecognizerDelegate>

@property (nonatomic, retain) ZSY_BaseImageView *headImageView;

@property (nonatomic, retain) ZSY_BaseLabel *nameLabel;



@end

@implementation ZSY_UserView

- (void)dealloc {
    [_nameLabel release];
    [_name release];
    [_url release];
    [_headImageView release];
    [super dealloc];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)setName:(NSString *)name {
    if (_name != name) {
        [_name release];
        _name = [name retain];
        self.nameLabel.text = _name;
    }
    
}

- (void)setUrl:(NSString *)url {
    if (_url != url) {
        [_url release];
        _url = [url retain];
        NSURL *url1 = [NSURL URLWithString:_url];
        [self.headImageView sd_setImageWithURL:url1];
    }
}

- (void)setProfileURL:(NSString *)profileURL {
    if (_profileURL != profileURL) {
        [_profileURL release];
        _profileURL = [profileURL retain];
    }
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    return self;
}



- (void)createSubviews {
    self.backImageView = [[ZSY_BaseImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, (HEIGHT - 40) / 2)];
//    backImageView.image = [UIImage imageNamed:@"bundle_spot_edit_default_cover"];
    
    [self addSubview:_backImageView];
    _backImageView.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.backImageView addGestureRecognizer:tap];
    tap.delegate = self;
    [tap release];
    
    
    self.headImageView = [[ZSY_BaseImageView alloc] initWithFrame:CGRectMake((WIDTH - 90) / 2, 50, 90, 90)];
    self.headImageView.backgroundColor = [UIColor yellowColor];
    self.headImageView.layer.cornerRadius = 45;
    self.headImageView.layer.masksToBounds = YES;
    [_backImageView addSubview:_headImageView];
    self.headImageView.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *headTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(headTapAction:)];
    [self.headImageView addGestureRecognizer:headTap];
    headTap.delegate = self;
    [headTap release];
    
    [_headImageView release];
    
    ZSY_BaseLabel *fansLabel = [[ZSY_BaseLabel alloc] initWithFrame:CGRectMake((WIDTH - 210) / 2, 110, 40, 20)];
    fansLabel.text = @"粉丝";
    fansLabel.font = [UIFont systemFontOfSize:14];
    fansLabel.textColor = [UIColor whiteColor];
    [_backImageView addSubview:fansLabel];
    [fansLabel release];
    
    ZSY_BaseLabel *attentionLabel = [[ZSY_BaseLabel alloc] initWithFrame:CGRectMake(WIDTH / 2 + 75, 110, 40, 20)];
    attentionLabel.textColor = [UIColor whiteColor];
    attentionLabel.text = @"关注";
    attentionLabel.font = [UIFont systemFontOfSize:14];
    [_backImageView addSubview:attentionLabel];
    [attentionLabel release];
    
    self.nameLabel = [[ZSY_BaseLabel alloc] initWithFrame:CGRectMake((WIDTH - 100) / 2, 150, 100, 20)];
    self.nameLabel.textColor = [UIColor whiteColor];
    self.nameLabel.text = @"123443";
    self.nameLabel.textAlignment = NSTextAlignmentCenter;
//    [self.nameLabel sizeToFit];
    [_backImageView addSubview:_nameLabel];
    
    ZSY_BaseButton *messageButton = [ZSY_BaseButton buttonWithType:UIButtonTypeCustom];
    messageButton.frame = CGRectMake(WIDTH / 2 - 110, 180, 100, 40);
    messageButton.backgroundColor = [UIColor whiteColor];
    messageButton.layer.cornerRadius = 20;
    messageButton.layer.masksToBounds = YES;
    [messageButton setTitle:@"消息" forState:UIControlStateNormal];
    messageButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [messageButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [_backImageView addSubview:messageButton];
    [messageButton addTarget:self action:@selector(messageButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    ZSY_BaseButton *orderButton = [ZSY_BaseButton buttonWithType:UIButtonTypeCustom];
    orderButton.frame = CGRectMake(WIDTH / 2 + 10, 180, 100, 40);
    orderButton.backgroundColor = [UIColor whiteColor];
    orderButton.layer.cornerRadius = 20;
    orderButton.layer.masksToBounds = YES;
    [orderButton setTitle:@"微博" forState:UIControlStateNormal];
    [orderButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    orderButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [_backImageView addSubview:orderButton];
    [orderButton addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [_backImageView release];
}

- (void)headTapAction:(UITapGestureRecognizer *)headTap {
    NSLog(@"正在点击头像");
    [self.myDelegate loginToSina];
}

- (void)tapAction:(UITapGestureRecognizer *)tap {
    NSLog(@"正在点击图片");
    [self.myDelegate changeBackgrandImage];
}

- (void)messageButtonAction:(ZSY_BaseButton *)button {
    NSLog(@"正在点击消息按钮");
}

- (void)orderButtonAction:(ZSY_BaseButton *)button {
    NSLog(@"正在点击微博按钮");
    NSLog(@"profileURL = %@", _profileURL);
    [self.myDelegate pushToweibo:_profileURL];
}


@end
